# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: signalTest halt matmult twomatmults sort proj3fork proj3exec waitTest broadcastTest lockTest cvTest

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

driver.o: driver.c
	$(CC) $(CFLAGS) -c driver.c
driver: driver.o start.o
	$(LD) $(LDFLAGS) start.o driver.o -o driver.coff
	../bin/coff2noff driver.coff driver

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

twomatmults.o: twomatmults.c
	$(CC) $(CFLAGS) -c twomatmults.c
twomatmults: twomatmults.o start.o
	$(LD) $(LDFLAGS) start.o twomatmults.o -o twomatmults.coff
	../bin/coff2noff twomatmults.coff twomatmults

proj3fork.o: proj3fork.c
	$(CC) $(CFLAGS) -c proj3fork.c
proj3fork: proj3fork.o start.o
	$(LD) $(LDFLAGS) start.o proj3fork.o -o proj3fork.coff
	../bin/coff2noff proj3fork.coff proj3fork

proj3exec.o: proj3exec.c
	$(CC) $(CFLAGS) -c proj3exec.c
proj3exec: proj3exec.o proj3exec.o
	$(LD) $(LDFLAGS) start.o proj3exec.o -o proj3exec.coff
	../bin/coff2noff proj3exec.coff proj3exec

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

testfiles.o: testfiles.c
	$(CC) $(CFLAGS) -c testfiles.c
testfiles: testfiles.o start.o
	$(LD) $(LDFLAGS) start.o testfiles.o -o testfiles.coff
	../bin/coff2noff testfiles.coff testfiles

proj2pa.o: proj2pa.c
	$(CC) $(CFLAGS) -c proj2pa.c
proj2pa: proj2pa.o start.o
	$(LD) $(LDFLAGS) start.o proj2pa.o -o proj2pa.coff
	../bin/coff2noff proj2pa.coff proj2pa

proj2pb.o: proj2pb.c
	$(CC) $(CFLAGS) -c proj2pb.c
proj2pb: proj2pb.o start.o
	$(LD) $(LDFLAGS) start.o proj2pb.o -o proj2pb.coff
	../bin/coff2noff proj2pb.coff proj2pb

proj2pb_test1.o: proj2pb_test1.c
	$(CC) $(CFLAGS) -c proj2pb_test1.c
proj2pb_test1: proj2pb_test1.o start.o
	$(LD) $(LDFLAGS) start.o proj2pb_test1.o -o proj2pb_test1.coff
	../bin/coff2noff proj2pb_test1.coff proj2pb_test1

proj2pb_test2.o: proj2pb_test2.c
	$(CC) $(CFLAGS) -c proj2pb_test2.c
proj2pb_test2: proj2pb_test2.o start.o
	$(LD) $(LDFLAGS) start.o proj2pb_test2.o -o proj2pb_test2.coff
	../bin/coff2noff proj2pb_test2.coff proj2pb_test2

#proj2pc.o: proj2pc.c
#	$(CC) $(CFLAGS) -c proj2pc.c
#proj2pc: proj2pc.o start.o
#	$(LD) $(LDFLAGS) start.o proj2pc.o -o proj2pc.coff
#	../bin/coff2noff proj2pc.coff proj2pc


#run_proj2.o: run_proj2.c
#	$(CC) $(CFLAGS) -c run_proj2.c
#run_proj2: run_proj2.o start.o
#	$(LD) $(LDFLAGS) start.o run_proj2.o -o run_proj2.coff
#	../bin/coff2noff run_proj2.coff run_proj2

waitTest.o: waitTest.c
	$(CC) $(CFLAGS) -c waitTest.c
waitTest: waitTest.o start.o
	$(LD) $(LDFLAGS) start.o waitTest.o -o waitTest.coff
	../bin/coff2noff waitTest.coff waitTest

signalTest.o: signalTest.c
	$(CC) $(CFLAGS) -c signalTest.c
signalTest: signalTest.o start.o
	$(LD) $(LDFLAGS) start.o signalTest.o -o signalTest.coff
	../bin/coff2noff signalTest.coff signalTest

broadcastTest.o: broadcastTest.c
	$(CC) $(CFLAGS) -c broadcastTest.c
broadcastTest: broadcastTest.o start.o
	$(LD) $(LDFLAGS) start.o broadcastTest.o -o broadcastTest.coff
	../bin/coff2noff broadcastTest.coff broadcastTest

lockTest.o: lockTest.c
	$(CC) $(CFLAGS) -c lockTest.c
lockTest: lockTest.o start.o
	$(LD) $(LDFLAGS) start.o lockTest.o -o lockTest.coff
	../bin/coff2noff lockTest.coff lockTest

cvTest.o: cvTest.c
	$(CC) $(CFLAGS) -c cvTest.c
cvTest: cvTest.o start.o
	$(LD) $(LDFLAGS) start.o cvTest.o -o cvTest.coff
	../bin/coff2noff cvTest.coff cvTest
clean:
	rm -f *.o *.coff
